home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
internet
/
yam_i_dodatki
/
yamtools1.7
/
ytdedup.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1997-06-29
|
13KB
|
348 lines
/******************************************************************************/
/* */
/* YTDeDup.rexx */
/* Copyright ©1997 by Dick Whiting */
/* */
/*----------------------------------------------------------------------------*/
/* This script requires YAMTOOLS for it to work. If you don't have YAMTOOLS */
/* you can get it on Aminet in directory comm/mail. This script allows you */
/* to locate and delete duplicate mail in a YAM folder. */
/*----------------------------------------------------------------------------*/
/* */
/* Logic: This script considers 2 mail to be duplicates IFF: */
/* 1) From fields are the same, AND */
/* 2) Subject fields are the same, AND */
/* 3) Date fields are the same, AND */
/* 4) Mail sizes in bytes are exactly the same. */
/* */
/*----------------------------------------------------------------------------*/
/* */
/* Standard Disclaimer: I wrote it, it works for me, I don't guarantee */
/* that it will do anything productive for anyone else, etc. etc. ;-) */
/* */
/*HOWEVER, if you DO find a use for it: I homeschool my kids and they */
/*would love a postcard from where EVER you live. */
/* */
/*Instant GEOGRAPHY lesson;) */
/* */
/* */
/*POSTCARDS: Dick Whiting */
/* 28590 S. Beavercreek Rd. */
/* Mulino, Oregon 97042 */
/* USA */
/* */
/*----------------------------------------------------------------------------*/
/* */
/* Address Bug Reports or Comments to: */
/* Dick Whiting <dwhiting@europa.com> */
/* 26 March 1997 */
/* */
/******************************************************************************/
/*
$VER: 1.0 Copyright ©1997 by Dick Whiting
$AUTHOR: Dick Whiting
$DESCRIPTION: Find and Delete Duplicate Mail in a YAM folder
*/
options results
options failat 9999 /* keep maildelete return from showing */
filename=''
rest=''
parse arg filename rest
/**************************************************************************/
/* Initialize Variables */
/**************************************************************************/
Call MUIvars /* go define vars for MUI use */
Call YTvars /* various values used in YT */
Call Helpvars /* pointers into HELP guide */
Call Localize /* vars for localizing strings*/
Call Builtvars /* built using previous values*/
/******************************************************************************/
/* MUIREXX TAGS & VARIABLES */
/******************************************************************************/
TRUE=1
FALSE=0
help.SQUIT=''
node.SQUIT=''
help.STEXT=''
node.STEXT=''
missing='.'
/**************************************************************************/
/* MAIN LOGIC FOR YTDEDUP.rexx */
/**************************************************************************/
Call CheckYam /* make sure Yam is running */
if filename='' then do
errmsg=_text._choosefold
Call ErrorMsg
end
Call GetMinfo /* get info for all mail in folder*/
Call FindDups /* sort array & identify dups */
Call DeleteDups /* go do the deletes */
exit
/**************************************************************************/
/* Get From and Subject using YAM facilities */
/* */
/* minfo array: from subject date mailnumber size */
/**************************************************************************/
GetMinfo:
minfo.=missing
minfo.0=0
Address YAM 'GetFolderInfo Number'
anum=result
Address YAM 'GetFolderInfo Max'
mailcnt=result
minfo.0=mailcnt
do i=0 to mailcnt-1
mnum=i
j=i+1
Address YAM 'Setmail' mnum
Address YAM 'Getmailinfo From'
mfrom=result
Address YAM 'Getmailinfo Subject'
msubj=result
Address YAM 'Getmailinfo File'
mpath=result
mdate=missing
msize=missing
Call GetDate
mstring=mfrom'|'mdate'|'msize'|'msubj'|'anum'|'mnum'|'mpath
minfo.j=mstring
end
Return
/**************************************************************************/
/* Read mail file for Date: line */
/**************************************************************************/
GetDate:
goodopen=open('IN',mpath,'R')
datefound=FALSE
if goodopen then do
finfo=statef(mpath)
parse var finfo type msize rest
do until eof('IN') | datefound
linein=readln('IN')
if linein='' then datefound=TRUE
if word(linein,1)='Date:' then do
mdate=subword(linein,2)
mdate=strip(mdate)
datefound=TRUE
end
end
result=close('IN')
end
else do
errmsg=_text._badmail
Call ErrorMsg
exit
end
Return
/**************************************************************************/
/* Sort mail info array and locate duplicates */
/**************************************************************************/
FindDups:
if show('L','rexxtricks.library') then do /* use tricks library */
call QSORT(minfo) /* sort by name, line number */
end
else do /* use QuickSort format */
call QSORT(1, minfo.0, minfo) /* sort by name, line number */
end
dinfo.=missing /* array of duplicates */
dinfo.0=0
oldfrom=missing /* set break values */
olddate=missing
oldsize=missing
oldsubj=missing
do i=1 to minfo.0
parse var minfo.i mfrom '|' mdate '|' msize '|' msubj '|' anum '|' mnum '|' mpath
if mfrom~=oldfrom | mdate~=olddate | msize~=oldsize | msubj~=oldsubj then do
oldfrom=mfrom
olddate=mdate
oldsize=msize
oldsubj=msubj
end
else do
j=1+dinfo.0
dinfo.0=j
dstring=anum'|'mnum'|'mpath
dinfo.j=dstring
end
end
Return
/**************************************************************************/
/* Sort Duplicate list, check for list change, do deletes */
/* Process in reverse list order to keep from changing list order */
/**************************************************************************/
DeleteDups:
if dinfo.0=0 then do /* no duplicates found */
errmsg=_text._nodups
Call ErrorMsg
exit
end
if show('L','rexxtricks.library') then do /* use tricks library */
call QSORT(dinfo)
end
else do /* use QuickSort format */
call QSORT(1, dinfo.0, dinfo)
end
do i=dinfo.0 to 1 by -1
parse var dinfo.i anum '|' mnum '|' mpath
Address YAM 'Setfolder' anum
Address YAM 'Setmail' mnum
Address YAM 'Getmailinfo File'
testpath=result
if mpath~=testpath then do
errmsg=_text._chgfolder
Call ErrorMsg
exit
end
Address YAM 'maildelete'
end
errmsg=dinfo.0||_text._maildeleted
Call ErrorMsg
exit
Return
/**************************************************************************/
/* Make sure YAM and YAMTOOLS are running. Show YAM. */
/**************************************************************************/
CheckYAM:
if ~show('p','YAMTOOLS') then do
errmsg=_text._noyt
say errmsg
exit
end
Address YAMTOOLS
if ~show('p','YAM') then do
errmsg=_text._noyam
Call ErrorMsg
exit
end
Address YAM 'show' /* uniconify YAM's screen */
Address YAM 'info SCREEN' /* get YAM's screen */
screen=result
if screen='' then screen='Workbench'
Return
/******************************************************************************/
/* Display ERROR message and EXIT. */
/******************************************************************************/
ErrorMsg:
Address YAMTOOLS
request ID ERRM GADGETS _text._ok errmsg
exit
Return
/******************************************************************************/
/* MUIREXX TAGS & VARIABLES */
/******************************************************************************/
Muivars:
TRUE=1
FALSE=0
Return
/**************************************************************************/
/* Various values used throughout the various routines */
/**************************************************************************/
YTvars:
missing='.'
Return
/**************************************************************************/
/* Messages, text, etc. constructed using previously defined values */
/**************************************************************************/
Builtvars:
Return
/**************************************************************************/
/* Pointers into the YamTools.guide documentation */
/**************************************************************************/
Helpvars:
node.SQUIT=''
node.STEXT=''
Return
/**************************************************************************/
/* Mui Gadgets, text, msgs, etc. used in YamTools */
/**************************************************************************/
Localize:
/*********************************/
/* Miscellaneous info strings */
/*********************************/
_text._ok='Ok' /* various OK buttons */
/*********************************/
/* Various error conditions */
/*********************************/
_text._noyam='You need YAM running to use YTDeDup' /* yam not running */
_text._noyt='You need YAMTOOLS running to use YTDeDup' /* no yamtools */
_text._chgfolder='Folder order has changed--quitting this folder'
_text._maildeleted=' mail(s) in folder deleted'
_text._nodups='No Duplicates Found in Folder'
_text._badmail='Unable to open a mailfile--exiting'
_text._choosefold='Choose Folder for Locating Similar Mail'
/**************************************************************************/
/* Help Messages to display with MUI bubble facility. */
/* */
/* Format is simple: help.ID where ID is the id specified on the MUI */
/* object statement. */
/* Similar approach for accessing the .guide information using the NODE */
/* option on the object statement. */
/* */
/**************************************************************************/
help.SQUIT=''
help.STEXT=''
Return